/*
package com.rykj.energy.task.message.mq;

import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rykj.energy.common.utils.SysConfig;
import com.rykj.energy.task.message.dto.MqDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;

@Component
@Slf4j
//@Lazy
public class ProductClient {
    public static int productMqPort = Integer.parseInt(SysConfig.getValue("product_mq_port", "5672"));
    public static String productMqHostName = SysConfig.getValue("product_mq_ip", "192.168.0.118");
    public static String productMqUser = SysConfig.getValue("product_mq_user", "ruiyan");
    public static String productMqPwd = SysConfig.getValue("product_mq_pwd", "ruiyan");
    Connection conn = null;
    public static String productExchangeName = SysConfig.getValue("product_mq_exchangeName", "ruiyanEX");
	public static String productRoutingKey = SysConfig.getValue("product_mq_routingKeyMsg", "routing_msg");
	public static String productQueue_msg = SysConfig.getValue("product_mq_queueMsg", "msg");
	public ProductClient() throws IOException, TimeoutException {
		init();
	}

	public void init() {
		try {
			ConnectionFactory factory = new ConnectionFactory();
			factory.setHost(productMqHostName);
			factory.setPort(productMqPort);
			factory.setUsername(productMqUser);
			factory.setPassword(productMqPwd);
			conn = factory.newConnection();
		} catch (Exception e) {
			log.error("mq连接异常,info:" + productMqHostName + "," + productMqPort + "," + productMqUser + "," + productMqPwd, e);
		}
	}
	public void sendMessage(String routingKey ,String msg) throws Exception {
	    sendMessage(productExchangeName, routingKey ,msg);
    }

	public void sendMessage(String exchangeName, String routingKey ,String msg) throws Exception {
//		log.info("==============================sendMessage start 【 exchangeName:"+exchangeName+",routingKey:"+routingKey+",msg:"+msg+" 】");
		Channel channel = null;
		channel = conn.createChannel();
		if(channel ==null){
			init();
			channel = conn.createChannel();
		}
		channel.exchangeDeclare(exchangeName, "direct",true);
		channel.basicPublish(exchangeName, routingKey, null, msg.getBytes("UTF-8"));
		log.info("==============================sendMessage end 【 exchangeName:"+exchangeName+",routingKey:"+routingKey+",msg:"+msg+" 】");
	}

	public void closeConn() {
		if(conn!=null){
			try {
				conn.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}



	*/
/**
	 * 提交mq
	 *//*

	public static void sendMq(List<MqDto> mqDtos) {
		if (mqDtos != null && mqDtos.size() > 0) {
			ProductClient producter = null;
			try {
				producter = new ProductClient();
				for (MqDto dto : mqDtos) {
					try {
						producter.sendMessage(dto.getExchangeName(), dto.getRoutingKey(), dto.getMsg() + "###");
					}catch (Exception e){
						log.error("消息发送异常,dto:" + JSONObject.toJSONString(dto),e);
					}
				}
			}catch (Exception e){
				log.error("mq消息发送异常",e);
			}finally {
				producter.closeConn();
			}
		}
	}

	*/
/**
	 * 提交mq
	 *//*

	public static void sendMq(MqDto mqDto) {
		ProductClient producter = null;
		try {
			producter = new ProductClient();
			//for (MqDto dto : mqDtos) {
			try {
				Channel channel = null;
				channel = producter.conn.createChannel();
				if(channel ==null){
					producter.init();
					channel = producter.conn.createChannel();
				}
				channel.exchangeDeclare(productExchangeName, "direct",true);
				channel.queueDeclare(mqDto.getQueue(), true, false, true, null);
				channel.queueBind(mqDto.getQueue(), productExchangeName,  mqDto.getRoutingKey());
				channel.basicPublish(productExchangeName, mqDto.getRoutingKey(), true, null, mqDto.getMsg().getBytes());
				log.info("==============================sendMessage end 【 exchangeName:"+productExchangeName+",routingKey:"+mqDto.getQueue()+",msg:"+mqDto.getMsg()+" 】");
			}catch (Exception e){
				log.error("消息发送异常,dto:" + JSONObject.toJSONString(mqDto),e);
			}
			//}
		}catch (Exception e){
			log.error("mq消息发送异常",e);
		}finally {
			producter.closeConn();
		}
	}

}
*/
